<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/20
  Time: 16:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/laypage.css">
    <script type="text/javascript" src="js/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="js/laypage/laypage.js"></script>
    <script type="text/javascript" src="js/layer/layer.js"></script>
    <script type="text/javascript" src="js/vue/vue.min.js"></script>
</head>
<body>
<div id="app" class="container">
    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" class="form-control" id="username" placeholder="用户名称">
        </div>
        <div class="form-group">
            <label class="sr-only" for="userage">用户密码</label>
            <input type="text" class="form-control" id="userage" placeholder="用户密码">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加用户</button>
    </form>
    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>用户</td>
                <td>密码</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.username}}</td>
                <td>{{item.password}}</td>
                <td><a href="#" @click="editEvent(item.userid)">编辑</a>|<a href="#" @click="delEvent(item.userid)">删除</a></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
</body>
</html>
<script>
    var app=new Vue({
        el:'#app',
        data:{
            result:[]
        }
    });
    /*列表展示begin*/
    var getUserPageList = function (curr) {

        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/user/getcond.do',
            data:{
                pageNum:curr|| 1,
                pageSize:3,
                username:$("#username").val()
            },
            success:function (msg){
                console.log(msg)
               /* alert(msg.page)*/
                app.result=msg.page.result;

                laypage({
                    cont: 'pagenav',
                    pages: msg.page.totalPage,
                    skip: true,
                    skin: '#7B68EE',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getUserPageList(obj.curr);
                        }
                    }
                });
            }
        })
    }
    $("#findUser").on("click",function(){
        getUserPageList();
    })
    getUserPageList();
    /*over*/
    /**
     * 新增用户
     */
    $("#addUserBtn").on("click", function () {
        layer.open({
            type: 2,
            title: '新增用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px','500px'],
            content: '/user/addUser.do',
            end: function () {
                getUserPageList();
            }
        });
    });
    /**
     * 删除用户
     */
    var delEvent=function (userid) {
        //弹出框
        layer.confirm('您确定要删除吗？',{
                //按钮
                btn:['是','否']
            },function () {
                //是
                $.ajax({
                    type:'GET',
                    dataType:'json',
                    url:'/user/delUser.do',
                    data:{
                        userid:userid
                    },
                    success:function (msg) {
                        getUserPageList();
                        layer.msg('已经成功删除记录'+userid,{icon:5});
                    }
                })
            },function () {
                //否
                layer.msg('感谢手下留情！',{icon:6});
            }
        )
    }
    //编辑
    var editEvent = function (userid) {
        layer.open({
            type: 2,
            title:'编辑用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['800px', '500px'],
            content: '/user/findUser.do?userid=' +userid,
            end: function () {
                getUserPageList();
            }
        });
    }
</script>
